var fammerForm = new Vue({
	el: '#fammerForm',
	data: {
		area:[],
		name:'',
		familys:'',
		address:'',
		mobile:'',
		poor:'',
		createBy:'',
		idcard:'',
		wd:'',
		jd:''
	},
	
	
	watch: {　　　　　

	},
	mounted: function() {
	this.createBy = localStorage.localuserid
	},
	methods: {
				getGPS: function() {

			var _this = this
			//自动获取经纬度
			plus.geolocation.getCurrentPosition(function(p) {
				_this.wd = p.coords.latitude
				_this.jd = p.coords.longitude
				console.log(_this.wd)
			}, function(e) {
				alert('获取gps定位失败: ' + e.message);
			});
			setTimeout(function() {
				plus.nativeUI.closeWaiting()
			}, 100);
		},
		submit:function(){
			if(this.wd.length <= 0 || this.jd.length<=0) {
				mui.alert("获取gps定位失败,请刷新后重试")
				return
			}
			//表单信息验证
			if(this.area.length<=0){
				mui.alert("请选择行政区域")
				return
			}
			if(this.name.length<=0){
				mui.alert("请填写户主姓名")
				return
			}
			if(this.familys.length<=0){
				mui.alert("请填写农户家庭人口数量")
				return
			}
			if(this.idcard.length<=0){
				mui.alert("请填写户主身份证号")
				return
			}
				if(this.address.length<=0){
				mui.alert("请填写农户家庭住址")
				return
			}
					if(this.mobile.length<=0){
				mui.alert("请填写联系电话")
				return
			}
						if(this.poor.length<=0){
				mui.alert("请选择是否贫困户")
				return
			}
							var areastr = '';	
						for(var i = 0; i < this.area.length; i++) {
				if(i==0){
					areastr  = this.area[i]
				}else{
			
					areastr  = areastr +","+ this.area[i]
				}
						
			}
				plus.nativeUI.showWaiting();
				var _this = this	
				axios({
				url: sever + '/saveFammer',
				method: 'POST',
				// 请求体重发送的数据
				params: {
				gps:_this.wd+","+_this.jd,areaName:document.getElementById("showCityPicker3").value,idCard:_this.idcard,createBy:_this.createBy,area:areastr,name:_this.name,familys:_this.familys,address:_this.address,mobile:_this.mobile,poor:_this.poor
				},
				timeout: 50000,
				// 设置请求头
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}).then(function(res) {
				plus.nativeUI.closeWaiting(); 
				if(res.data.success){
					mui.alert("农户信息提交成功",function(){
						/*document.getElementById("form").reset()*/
							var old_back = mui.back;
						old_back();
					})
				}else{
					mui.alert(res.data.msg)
				}
				
			})		
			
		},
	},
});